<template>
  <div>
    <!--头部导航栏-->
    <Header></Header>
    <!--/头部导航栏-->
    <div class="body-center">
      <div class="home_wrap">
        <!-- 首页导航栏 -->
        <div class="floor_nav">
          <div class="blog_nav">
            <div class="blog-nav-tag">
              <ul class="def">
                <li class="menustitle" title="后端">
                  <a @click="toSearch(d.idCard)">
                    后端
                  </a>
                </li>
                <li class="menustitle" title="前端">
                  <a @click="toSearch(d.idCard)">
                    前端
                  </a>
                </li>
                <li class="menustitle" title="移动开发">
                  <a @click="toSearch(d.idCard)">
                    移动开发
                  </a>
                </li>
                <li class="menustitle" title="编程语言">
                  <a @click="toSearch(d.idCard)">
                    编程语言
                  </a>
                </li>
                <li class="menustitle" title="Java">
                  <a @click="toSearch(d.idCard)">
                    Java
                  </a>
                </li>
                <li class="menustitle" title="Python">
                  <a @click="toSearch(d.idCard)">
                    Python
                  </a>
                </li>
                <li class="menustitle" title="人工智能">
                  <a @click="toSearch(d.idCard)">
                    人工智能
                  </a>
                </li>
                <li class="menustitle" title="大数据">
                  <a @click="toSearch(d.idCard)">
                    大数据
                  </a>
                </li>
                <li class="menustitle" title="数据结构与算法">
                  <a @click="toSearch(d.idCard)">
                    数据结构与算法
                  </a>
                </li>
                <li class="menustitle" title="音视频">
                  <a @click="toSearch(d.idCard)">
                    音视频
                  </a>
                </li>
                <li class="menustitle" title="云原生">
                  <a @click="toSearch(d.idCard)">
                    云原生
                  </a>
                </li>
                <li class="menustitle" title="云平台">
                  <a @click="toSearch(d.idCard)">
                    云平台
                  </a>
                </li>
                <li class="menustitle" title="运维">
                  <a @click="toSearch(d.idCard)">
                    运维
                  </a>
                </li>
                <li class="menustitle" title="服务器">
                  <a @click="toSearch(d.idCard)">
                    服务器
                  </a>
                </li>
                <li class="menustitle" title="操作系统">
                  <a @click="toSearch(d.idCard)">
                    操作系统
                  </a>
                </li>
                <li class="menustitle" title="数据库管理">
                  <a @click="toSearch(d.idCard)">
                    数据库管理
                  </a>
                </li>
              </ul>
            </div>
          </div>
        </div>
        <!-- /首页导航栏 -->
        <div class="home_title">
          <div id="kp_box_ww9877"></div>
        </div>
        <!-- 首页资讯展示 -->
        <div class="home_content">
          <div class="headlines">
            <!-- 头条资讯展示栏 -->
            <div class="headlines_left">
              <div class="top_title">
                <img src="../assets/toutiao.png" />
                <h3>头条</h3>
              </div>
              <dl v-for="item in tableData.slice(0 , 1 * 1)">
                <dt>
                  <a @click="toConsult(item.id)">
                    <img src="../assets/indeximg1.jpg" alt data-v-indeximg1 />
                  </a>
                </dt>
                <dd class="desc" data-v-indeximgtitle>
                  <a @click="toConsult(item.id)" data-v-e8da5228>
                    {{item.newHead}}
                  </a>
                </dd>
                <dd class="desc-text-a" data-v-e8da5229>
                  <a @click="toConsult(item.id)" data-v-e8da5229>
                    {{item.newsBody}}
                  </a>
                </dd>
              </dl>
            </div>
            <div class="headlines_right">
              <div class="headswiper">
                <div class="headswiper-top"></div>
                <div class="headswiper-content">
                  <div data-v-0045335f>
                    <div data-v-0045335f class="headswiper-item" v-for="item in tableData.slice(1 , 1 * 6)">
                      <a data-v-0045335f class="title" @click="toConsult(item.id)">
                        <strong>{{item.newHead}}</strong>
                      </a>
                      <a data-v-0045335f @click="toConsult(item.id)">
                        <p data-v-0045335f class="name">{{item.newsBody}}</p>
                      </a>
                    </div>
                  </div>
                </div>
              </div>
              <!-- /头条资讯展示栏 -->

              <!-- 热点资讯展示栏 -->
              <div class="headswiper">
                <div class="headswiper-top">
                  <div class="top_title">
                    <img src="../assets/redian.png" alt data-v-0045335f />
                    <h3 data-v-0045335f>热点</h3>
                  </div>
                </div>
                <div class="headswiper-content">
                  <div data-v-0045335f>
                    <div data-v-0045335f class="headswiper-item" v-for="item in tableData.slice(6 , 1 * 11)">
                      <a data-v-0045335f class="title" @click="toConsult(item.id)">
                        <strong>{{item.newHead}}</strong>
                      </a>
                      <a data-v-0045335f @click="toConsult(item.id)">
                        <p data-v-0045335f class="name">{{item.newsBody}}</p>
                      </a>
                    </div>
                  </div>
                </div>
              </div>
              <!-- /热点资讯展示栏 -->
            </div>

          </div>
          <!-- 右侧广告栏 -->
          <div class="broadcast-active">
            <img src="../assets/gg1.png" />
          </div>
          <!-- /右侧广告栏 -->
        </div>
        <!-- /首页资讯展示 -->

        <!-- 底部列表 -->
        <div class="www-home">
          <div>
            <div class="www-home-left" style="min-height: 300px;">
              <table>
                <thead>
                  <tr>
                    <td class="table_title">
                      <a href="/"><span>关注</span></a>
                      <a href="/"><span>推荐</span></a>
                      <a href="/"><span>资讯</span></a>
                      <a href="/"><span>热榜</span></a>
                      <a href="/"><span>专家推荐</span></a>
                    </td>
                    <td class="table_title_more">
                      <a @click="toSearch(d.idCard)"><span>更多</span></a>
                    </td>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="item in tableData">
                    <td colspan="2">
                      <div class="table_list">
                        <div class="list_hr"></div>
                        <div class="list_body">
                          <div class="list_title">
                            <a @click="toConsult(item.id)"><span>{{item.newHead}}</span></a>
                          </div>
                          <div class="list_constant">
                            <a @click="toConsult(item.id)"><span>{{item.newsBody}}</span></a>
                            <a
                              @click="toConsult(item.id)"><span>类别:{{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;作者:{{item.createName}}&nbsp;&nbsp;&nbsp;&nbsp;发布时间:{{item.newsTime}}</span></a>
                          </div>
                        </div>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>

        </div>
        <!-- /底部列表 -->
        <!--页脚-->
        <Footer></Footer>
        <!--/页脚-->
      </div>
    </div>
  </div>
</template>

<script>
  import Footer from "../components/Footer";
  import Header from "../components/Header";
  export default {
    name: "Index",
    data() {
      return {
        title: '',
        tableData: [{}] /*查询所有用户*/ ,
        d: {} /*查询单条博客*/ ,
      }
    },
    components: {
      Footer,
      Header
    },
    methods: {
      toConsult(id) {
        this.$router.push({
          name: 'Consult',
          params: {
            id: id
          }
        });
      },
      /*单个id查询用户*/
      findUserById(id) {
        this.updateFormVisible = true
        let _this = this
        console.log(id)
        this.$axios.get("http://localhost:8087/user/getUserById/" + id).then(function(res) {
          _this.d = res.data
        }).catch(function(err) {
          _this.$message('请登录哦~');
        })
      },

      /* 博客页面跳转 */
      toSearch(id){
        this.$router.push({ name: 'Search', params: { id: id }});
      },

      /*查询所有的资讯*/
      findAll() {
        let _this = this;
        this.$axios
          .get('http://localhost:8087/news/selectNews')
          .then(function(res) {
            _this.tableData = res.data;
            console.log(res.data);
          })
          .catch(function(err) {
            alert('查询失败');
          });
      },
      /*模糊查询某类型的资讯*/
      findTypeAll(type) {
        console.log(type)
        let _this = this
        this.$axios.post("http://localhost:8087/news/selectNewsByType/" + type).then(function(res) {
          _this.tableData = res.data;
          console.log(res.data);
        })
        .catch(function(err) {
          alert('查询失败');
        });
      }
    },
    mounted() {
      this.findUserById(localStorage.getItem("id"));
      this.findAll()
    }
  }
</script>

<style scoped>
  .body-center {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    font-family: PingFang SC, Hiragino Sans GB, Arial, Microsoft YaHei, Verdana, Roboto, Noto, Helvetica Neue, sans-serif;
  }

  .home_wrap {
    background-color: hsla(0, 0%, 98%, .8);
    -webkit-font-smoothing: antialiased;
  }

  .floor_nav {
    margin-top: 10px;
    height: 72px;
    width: 100%;
  }

  .blog_nav {
    width: 1380px;
    margin: 10px auto 0;
    -webkit-box-shadow: 0 4px 30px 0 rgba(232, 232, 237, .5);
    box-shadow: 0 4px 30px 0 rgba(232, 232, 237, .5);
    border-radius: 4px;
  }

  .blog-nav-tag {
    width: 100%;
    height: 72px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: start;
    -ms-flex-align: start;
    align-items: center;
    background: #fff;
    position: relative;
  }

  .blog-nav-tag ul li {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    position: relative;
    padding-bottom: 8px;
    top: 0;
    width: auto;
    height: 100%;
    float: left;
    list-style: none;
    display: block;
  }

  .menustitle a {
    text-decoration: none;
    font-family: "PingFang SC,Hiragino Sans GB,Arial,Microsoft YaHei,Verdana,Roboto,Noto,Helvetica Neue,sans-serif";
    font-size: 15px;
    display: block;
    height: 100%;
    color: inherit;
    padding: 0 15px;
  }

  .home_title {
    width: 1380px;
    margin: 0 auto;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
  }

  #kp_box_ww9877 {
    width: 100%;
    margin-top: 50px;
  }

  .home_content {
    margin-top: 26px;
    margin-bottom: 24px;
    width: 1380px;
    margin: 0 auto;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
  }

  .headlines {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    height: 400px;
    border-radius: 2px;
  }

  .headlines_left {
    width: 420px;
  }

  .headlines_left img {
    width: 24px;
    height: 24px;
    margin-right: 4px;
  }

  .headlines_left h3 {
    font-size: 18px;
    font-weight: 700;
    color: #222226;
  }

  .headlines_left dt img[data-v-indeximg1] {
    width: 100%;
    height: 232px;
    border-radius: 2px;
  }

  .headlines_left a[data-v-e8da5228],
  .desc[data-v-indeximgtitle] {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    word-break: break-all;
  }

  .headlines_left a[data-v-e8da5228] {
    text-decoration: none !important;
    font-size: 17px;
    font-weight: 700;
    color: #222226;
    margin-bottom: 6px;
  }

  .headlines_left .desc[data-v-indeximgtitle] {
    margin-top: 8px;
    -webkit-line-clamp: 2;
  }

  .desc-text-a a[data-v-e8da5229] {
    max-height: 48px;
    -webkit-line-clamp: 2;
    color: #999AAA;
    line-height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }

  .top_title {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    margin-bottom: 16px;
  }

  .headlines_right {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
  }

  .headswiper {
    width: 304px;
    height: 100%;
  }

  .headswiper-top {
    padding: 0 24px;
    height: 24px;
    line-height: 24px;
  }

  .headswiper .headswiper-content {
    padding: 0 24px;
  }

  .headswiper .headswiper-content .headswiper-item[data-v-0045335f] {
    margin-top: 16px;
  }

  .headswiper .headswiper-content .headswiper-item .title[data-v-0045335f] {
    color: #222226;
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    word-break: break-all;
  }

  .headswiper .headswiper-item .title strong {
    font-weight: 700;
  }

  .headswiper .headswiper-content .headswiper-item .name[data-v-0045335f] {
    margin-top: 4px;
    font-size: 14px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    word-break: break-all;
  }

  a {
    text-decoration: none !important;
  }

  .headswiper-top {
    padding-right: 24px;
  }

  .headswiper img[data-v-0045335f] {
    width: 24px;
    height: 24px;
    margin-right: 4px;
  }

  .headswiper h3[data-v-0045335f] {
    font-size: 18px;
    font-weight: 700;
    color: #222226;
  }

  .broadcast-active {
    width: 338px;
    height: 400px;
    border-radius: 2px;
    overflow: hidden;
  }

  .broadcast-active img {
    width: 338px;
    height: 400px;
  }

  .www-home {
    width: 100%;
    background: #fff;
    padding-top: 16px;
  }

  .www-home>div {
    width: 1380px;
    margin: 0 auto;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
  }

  .table_title {
    height: 48px;
  }

  .table_title span {
    font-size: 16px;
    color: #999AAA;
    margin-right: 56px;
    position: relative;
    line-height: 56px;
    cursor: pointer;
  }

  .table_title_more span {
    font-size: 16px;
    color: #999AAA;
  }

  .table_list {
    width: 1015px;
    min-height: 80px;
  }

  .list_hr {
    height: 1px;
    background-color: #f5f6f7;
    margin: auto;
  }

  .list_body {}

  .list_title span {
    padding-top: 10px;
    font-size: 18px;
    font-weight: 500;
    color: #222226;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    font-family: "微软雅黑";
    font-weight: bold;
    -webkit-line-clamp: 1;
    line-height: 25px;
  }

  .list_constant span {
    padding-top: 10px;
    padding-left: 20px;
    max-height: 48px;
    -webkit-line-clamp: 2;
    color: #999AAA;
    line-height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }
</style>
